﻿using System.Reflection;
using NUnit.Framework;
using OpenWaves.Reflection;
using OpenWaves.Web;
using System.Linq;

namespace OpenWaves.Testing.CodeAnalysisRules
{
    public class PublicAssemblyResourceAttributesShouldPointToValidResources : ICodeAnalysisRule
    {
        public void Run(Assembly assembly)
        {
            var embededResources = assembly.GetManifestResourceNames();

            foreach(var resourceName in assembly.GetCustomAttributes<PublicAssemblyResourcesAttribute>().SelectMany(a=>a.ResourceNames))
            {
                Assert.Contains(resourceName, embededResources, "Public Assembly Resource {0} is not embeded in the assembly {1}.", resourceName, assembly);    
            }
        }
    }
}